package com.example.hello.service.impl;

import com.example.hello.entity.Company;
import com.example.hello.entity.Factory;
import com.example.hello.entity.Device;
import com.example.hello.mapper.CompanyMapper;
import com.example.hello.mapper.FactoryMapper;
import com.example.hello.mapper.DeviceMapper;
import com.example.hello.service.AssetService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class AssetServiceImpl implements AssetService {

    @Autowired
    private CompanyMapper companyMapper;

    @Autowired
    private FactoryMapper factoryMapper;

    @Autowired
    private DeviceMapper deviceMapper;

    @Override
    public PageInfo<Company> getCompanies(int page, int limit) {
        PageHelper.startPage(page, limit);
        List<Company> companies = companyMapper.selectAll();
        return new PageInfo<>(companies);
    }

    @Override
    public PageInfo<Factory> getFactories(int page, int limit, Integer companyId) {
        PageHelper.startPage(page, limit);
        List<Factory> factories = factoryMapper.selectByCompanyId(companyId);
        return new PageInfo<>(factories);
    }

    @Override
    public PageInfo<Device> getDevices(int page, int limit, Integer factoryId) {
        PageHelper.startPage(page, limit);
        List<Device> devices = deviceMapper.selectByFactoryId(factoryId);
        return new PageInfo<>(devices);
    }
} 